<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/15
 * Time: 11:47
 */

namespace app\api\model;


class Collage extends BaseModel
{
    //在执行前
    public static function checkCollage()
    {
        $collage = self::where('status','neq',4)->select();
        $now = date('Y-m-d H:i:s');
        $collages = [];
        foreach($collage as $k=>$v){
            if($now < $v->getData('start_time')){
                self::where(['id'=>$v->getData('id')])->update(['status'=>1]);
            }elseif($now > $v->getData('end_time')){
                self::where(['id'=>$v->getData('id')])->update(['status'=>3]);
            }else{
                self::where(['id'=>$v->getData('id')])->update(['status'=>2]);
                $collages[] = $v;
            }
        }
        return $collages;
    }

    public function collageGoods()
    {
        return $this->belongsTo('Goods','goods_id','id');
    }

    //获取数据后检验活动是否在进行中
    public static function proofCollage($start_time,$end_time)
    {
        $now = date('Y-m-d H:i:s');
        if(($now > $start_time) && ($now < $end_time)){
            return true;
        }else{
            return false;
        }
    }
}